package com.bizark.rpc.api.service;

import com.bizark.rpc.api.bean.inventory.InventoryLists;
import com.bizark.rpc.api.bean.inventory.InventorySanpshots;
import com.bizark.rpc.core.mapper.inventory.InventoryListsMapper;
import com.bizark.rpc.core.mapper.inventory.InventorySanpshotsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by tsj on 2017/3/10.
 */
@Component
@Lazy(false)
public class InventoryTask {

    @Autowired
    private InventoryListsMapper inventoryListsMapper;

    @Autowired
    private InventorySanpshotsMapper inventorySanpshotsMapper;

    /**
     * 统计定时任务
     */
//    @Scheduled(cron="0 0/1 * * * ?")
    public void doSomething() {
        List<InventoryLists> map =  inventoryListsMapper.selectLastTen();

        for(InventoryLists aa:map){

            int i = inventorySanpshotsMapper.selectIsOnly(aa.getOrganizationId(),aa.getProductId());
            if(i==0){
                InventorySanpshots sanpshots = new InventorySanpshots();
                sanpshots.setOrganizationId(aa.getOrganizationId());
                sanpshots.setTransactionOrgId(aa.getTransactionOrgId());
                sanpshots.setLineId(aa.getLineId());
                sanpshots.setDepotId(aa.getDepotId());
                sanpshots.setProductId(aa.getProductId());
                sanpshots.setItemsku(aa.getItemsku());
                sanpshots.setDepotsku(aa.getDepotsku());
                sanpshots.setInventoryAvailable(aa.getInventoryAvailable());
                sanpshots.setInventoryLoss(aa.getInventoryLoss());
                sanpshots.setInventoryCost(aa.getInventoryCost());
                sanpshots.setInventoryCurrent(aa.getInventoryCurrent());
                sanpshots.setInventoryReserved(aa.getInventoryReserved());
                sanpshots.setInventoryTransport(aa.getInventoryTransport());
                sanpshots.setFobCost(aa.getFobCost());
                sanpshots.setOpId(aa.getOpId());
                sanpshots.setDepotsku(aa.getDepotsku());
                inventorySanpshotsMapper.insert(sanpshots);
            }
        }
    }

}
